package com.CST.common.method;

import com.CST.entity.BdEnumdetail;
import com.CST.mapper.dataplatform.BdEnumdetailMapper;
import com.CST.service.IBdEnumdetailService;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

public class CommonMethod {

    /**
     * 根据edParentCode获取最大edCode  BD_EnumDetil专用
     *
     * @param edParentCode
     * @return
     */
    public String maxEdCode(BdEnumdetailMapper baseMapper, String edParentCode) {

        String maxValue = "";
        try {
            BdEnumdetail entity = new BdEnumdetail();
            entity.setEdParentCode(edParentCode);
            List<BdEnumdetail> list = baseMapper.getEnumDetailSource(entity);
            if (CollectionUtils.isNotEmpty(list)) {
                List<String> stringList = list.stream().map(t -> t.getEdCode()).collect(Collectors.toList());
                List<Integer> integerList = stringList.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
                Integer max = integerList.stream().reduce(Integer::max).get();
                return String.valueOf(max + 1);
            }

        } catch (Exception ex) {
            return maxValue;
        }

        return maxValue;
    }

}
